#!/bin/bash

source src/conf/config.conf

open_url=http://www.mirrorservice.org/pub/OpenBSD/$openbsd_ver/$openbsd_arch/

echo " Downloading OpenBSD ..."

cd $tftp_dir


    for ARCH in i386 amd64; do
        mkdir -p "open/${ARCH}"

wget -q -c $open_url/bsd.rd && mv bsd.rd open/$openbsd_arch/
wget -q -c $open_url/pxeboot -O openbsd.0 && mv openbsd.0 open/$openbsd_arch/

 done
 
yes | cp -Rv open/* BSD/openbsd/

sleep 3
mv open/ tars/

## MENU
touch pxelinux/openbsd.cfg

cat >> pxelinux.cfg/bsd << EOF

stty com0 19200
set tty com0
boot tftp:/bsd.rd
menu include pxelinux.cfg/graphics.conf
MENU BACKGROUND pxelinux.cfg/background.png


MENU BEGIN oses-submenu
 LABEL Previous
        MENU LABEL Previous Menu
        TEXT HELP
        Return to previous menu
        ENDTEXT
        MENU EXIT
 MENU TITLE Install Open BSD
MENU INCLUDE pxelinux.cfg/openbsd.cfg
MENU END



EOF

    for ARCH in i386 amd64; do
        echo "label Install Open BSD  ${ARCH}"
        echo "      menu label Open BSD  ${ARCH}"
        echo "      kernel BSD/openbsd/${ARCH}/openbsd.0"
        echo "      append BSD/openbsd/${ARCH}/bsd.rd"
        echo "	   boot tftp:/BSD/openbsd/${ARCH}/bsd.rd"
   
echo " "
	echo " TEXT HELP"
       echo "  Install Open BSD ${ARCH}"
        echo " ENDTEXT"

done >> pxelinux.cfg/openbsd.cfg

